/**
 * Created by xl on 2016/4/26.
 */
(function($) {
    $("a[href$='#']").attr("href", "javascript:void(0);");
    $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $("html") : $("body")) : $("html,body");
    function traversalType(data,content,parentId){
        var str='',len=0;
        $.each(data, function (i, v) {
            str += '<li><a href="job_list.html?rd=' + v.id + '&paRd='+parentId+'" target="_blank">' + v.name + '</a></li>';
        });
        len=data.length || 0;
        if(len>0){
            content.addClass('job_'+len);
        }
        if (str == '') {
            content.find('span').hide();
        } else {
            content.find('ul').html(str);
        }
    }
    var support=hasSupport('placeholder','input');
    if(!support) {
        var mainEle = $(".search_box");
        $(".search_box .JSplaceholder").show();
        mainEle.on("focus", "input", function () {
            var self = $(this);
            var tipEle = self.next("i");
            tipEle.hide();
        }).on("blur", "input", function () {
            var self2 = $(this);
            var tipEle2 = self2.next("i");
            if ($.trim(self2.val()) == "") {
                tipEle2.show();
            }
        });
        mainEle.on('click', '.JSplaceholder', function () {
            var self = $(this);
            self.prev('input').focus();
        });
    }
    //填充职位类型
    var jobJs = $(".job_js");
    var jobCp = $(".job_cp");
    var jobYx = $(".job_yx");
    var jobZy = $(".job_zy");
    if (configData && configData.positiontype) {
        $.each(configData.positiontype, function (index, value) {
            if (value.name == '技术族') {
                jobJs.find(".job_tt a").attr({"href": "job_list.html?paRd=" + value.id, "target": "_blank"});
                traversalType(value.children, jobJs, value.id)
            } else if (value.name == '产品族') {
                jobCp.find(".job_tt a").attr({"href": "job_list.html?paRd=" + value.id, "target": "_blank"});
                traversalType(value.children, jobCp, value.id)
            } else if (value.name == '专业族') {
                jobZy.find(".job_tt a").attr({"href": "job_list.html?paRd=" + value.id, "target": "_blank"});
                traversalType(value.children, jobZy, value.id)
            } else if (value.name == '营销族') {
                jobYx.find(".job_tt a").attr({"href": "job_list.html?paRd=" + value.id, "target": "_blank"});
                traversalType(value.children, jobYx, value.id)
            } else {
            }
        });
    }
    //回到顶部
    $(".btn_totop").click(function (e) {
        stopPreEvent(e);
        $body.animate({scrollTop: 0}, 1000);
    });
    //人物介绍处有动画
    var txtRight=$(".txt_right");
    var txtLeft=$(".txt_left");
    $(window).scroll(function() {
        var topRange = $(document).scrollTop();
        if (!txtRight.hasClass("show")) {
            if (topRange >= 600 && topRange <= 800) {
                txtRight.addClass("show");
            }
        }
        if (!txtLeft.hasClass("show")) {
            if (topRange > 800 && topRange <= 900) {
                txtLeft.addClass("show");
            }
        }
    });
    //轮播one
    CarouselImg({
        imgEle: '.JSoneImgCon',
        imgEleChild: "li",
        imgChildClass: "show",
        prevImg: ".JSonePre",
        nextImg: ".JSoneNext",
        indexListEle: ".JSoneIndexCon",
        indexListChild: "a",
        indexListEleClass: "cur",
        carouseltime: 8000,
        carouseStyle: "leftCtro",
        imgWidth:1000
    });
    //轮播three
    CarouselImg({
        imgEle: '.JSthreeImgCon',
        imgEleChild: "li",
        imgChildClass: "show",
        indexListEle: ".JSthreeIndexCon",
        indexListChild: "a",
        indexListEleClass: "cur",
        carouseltime: 3000,
        carouseStyle: "classCtro"
    });
    /*(function CarouselIndex() {
     var curIndex = 0, //当前图片index
     imgContainer = $(".JSoneImgCon"), //图片容器
     JSoneIndexCon = $(".JSoneIndexCon"),//右下角序列号
     imgLen = imgContainer.find('li').length;//图片总数
     //自动切换定时器
     var autoChangeSp = setInterval(function () {
     if (curIndex < imgLen - 1) {
     curIndex++;
     } else {
     curIndex = 0;
     }
     changeTo(curIndex);
     }, 2000);
     //图片切换处理方法
     function changeTo(num) {
     imgContainer.find("li").removeClass('show').eq(num).addClass('show');
     JSoneIndexCon.find("a").removeClass("cur").eq(num).addClass("cur");
     }

     //重置定时器
     function autoChangeAgain() {
     autoChangeSp = setInterval(function () {
     if (curIndex < imgLen - 1) {
     curIndex++;
     } else {
     curIndex = 0;
     }
     changeTo(curIndex);
     }, 2000);
     }

     //左箭头事件
     var prev = $(".JSonePre");
     prev.hover(function () {
     //滑入清除
     clearInterval(autoChangeSp);
     }, function () {
     //滑出重置
     autoChangeAgain();
     });
     prev.click(function (e) {
     stopPreEvent(e);
     curIndex = (curIndex > 0) ? (--curIndex) : (imgLen - 1);
     changeTo(curIndex);
     });
     //右箭头事件
     var next = $(".JSoneNext");
     next.hover(function () {
     clearInterval(autoChangeSp);
     }, function () {
     autoChangeAgain();
     });
     next.click(function (e) {
     stopPreEvent(e);
     curIndex = (curIndex < imgLen - 1) ? (++curIndex) : 0;
     changeTo(curIndex);
     });
     //图片右下角或中部序号事件
     JSoneIndexCon.find('a').each(function (item) {
     $(this).hover(function () {
     clearInterval(autoChangeSp);
     changeTo(item);
     curIndex = item;
     }, function () {
     autoChangeAgain();
     });
     });
     })();*/
    //图片弹窗
    $(".pic_area").click(function () {
        $(".JSpop_area").show();
        if (!$(this).attr("isClick")) {
            //弹窗图片轮播
            CarouselImg({
                imgEle: '.JStwoImgCon',
                imgEleChild: "li",
                imgChildClass:"show",
                imgWidth: 956,
                prevImg: ".JStwoPrev",
                nextImg: ".JStwoNext",
                indexListEle: ".JStwoIndexCon",
                indexListChild: "a",
                carouseltime: 2000,
                indexListEleClass: "cur",
                special:true,
                carouseStyle:"classCtro"
            });
            $(this).attr("isClick", "true");
        }
    });
    //图片弹窗关闭
    $(".JSbtnclose").click(function (e) {
        stopPreEvent(e);
        $(".JSpop_area").hide();
    });
    //职位搜索
    $(".btn_search").click(function(e){
        stopProEvent(e);
        stopPreEvent(e);
        window.open(encodeURI('job_list.html?search='+$(".JSsearch").val()));
    });
    $(".JSsearch").keydown(function(event) {
        var e = event || window.event;
        var code = e.keyCode || e.which || e.charCode;
        if (code == 13) {
            //回车
            window.open(encodeURI('job_list.html?search='+$(".JSsearch").val()));
            return false;
        }
    });
})(jQuery);